package cn.stylefeng.guns.modular.hx.storage.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hx.storage.entity.TurnoverContainerDetailed;
import cn.stylefeng.guns.modular.hx.storage.mapper.TurnoverContainerDetailedMapper;
import cn.stylefeng.guns.modular.hx.storage.model.params.TurnoverContainerDetailedParam;
import cn.stylefeng.guns.modular.hx.storage.model.result.TurnoverContainerDetailedResult;
import  cn.stylefeng.guns.modular.hx.storage.service.TurnoverContainerDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 周转容器管理明细 服务实现类
 * </p>
 *
 * @author 
 * @since 2024-04-22
 */
@Service
public class TurnoverContainerDetailedServiceImpl extends ServiceImpl<TurnoverContainerDetailedMapper, TurnoverContainerDetailed> implements TurnoverContainerDetailedService {

    @Override
    public void add(TurnoverContainerDetailedParam param){
        TurnoverContainerDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TurnoverContainerDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TurnoverContainerDetailedParam param){
        TurnoverContainerDetailed oldEntity = getOldEntity(param);
        TurnoverContainerDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TurnoverContainerDetailedResult findBySpec(TurnoverContainerDetailedParam param){
        return null;
    }

    @Override
    public List<TurnoverContainerDetailedResult> findListBySpec(TurnoverContainerDetailedParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TurnoverContainerDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TurnoverContainerDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TurnoverContainerDetailed getOldEntity(TurnoverContainerDetailedParam param) {
        return this.getById(getKey(param));
    }

    private TurnoverContainerDetailed getEntity(TurnoverContainerDetailedParam param) {
        TurnoverContainerDetailed entity = new TurnoverContainerDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }


}
